package com.jyt.controller;

import com.github.pagehelper.PageInfo;
import com.jyt.entities.Check;
import com.jyt.response.Result;
import com.jyt.response.ResultCode;
import com.jyt.service.CheckService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 查询所有的相关数据库信息
 * @Author hugh.sun
 * @Date 2021/11/24 16:34
 */
@Api
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/Query")
public class QueryController {
    @Autowired
    private CheckService checkService;


    @GetMapping("/findAll")
    public Result findAll(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize") Integer pageSize){
        try {
            PageInfo<Check> allCheck = checkService.findAll(pageNum,pageSize);
            return  Result.ok().data("findAll",allCheck);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultCode.COMMON_FAIL);
        }

    }
    /*查询所有 模糊查询 三个值，一个vo 两个分页相关*/
    @GetMapping("/findAllCheck")
    public Result findAllCheck(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,Check check){

        try {
            PageInfo<Check> allCheck = checkService.findAllCheck(pageNum,pageSize,check);
            return Result.ok().data("findAllCheck",allCheck);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultCode.COMMON_FAIL);
        }
    }

    @PutMapping("/addCheck")
    public Result addCheck(Check check){

        try {
            checkService.addCheck(check);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultCode.COMMON_FAIL);
        }
    }

    @PostMapping("/export")
    public Result export(){

        try {
            checkService.excel();
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultCode.COMMON_FAIL);
        }
    }
}
